clear
rng default

workers=500;
 
n_grids=6;

fp0='.../r4/[5]/Figure_C1'; %add correct path

for h=1:n_grids

fp=['.../r4/[5]/Figure_C1/M_grid', int2str(h)]; 


IdSetM_temp=cell(workers,1);
for ii = 1:workers
    filepath = fullfile( fp, ['IdSetM.' num2str(ii) '.mat'] );
    if exist( filepath, 'file' )
       A = getfield( load( filepath ), 'IdSetM' ); 
       IdSetM_temp{ii}=A;
    end
end
IdSetM_final_grid= vertcat(IdSetM_temp{:}); 

outpath = fullfile( fp0, ['IdSetM_final_grid' num2str(h) '.mat'] );
save( outpath, 'IdSetM_final_grid' );
end
 
 


 

